<?php
/**
 * RegistrationForm class.
 * RegistrationForm is the data structure for keeping
 * user registration form data. It is used by the 'registration' action of 'UserController'.
 */
class JUserForm extends CActiveForm {
    public $verifyPassword;
    public $verifyCode;

    public $user_type;
    public $user_title;

    public function tableName()
    {
        return '{{profiles}}';
    }

    public function attributeLabels()
    {
        return array(
            'user_id' => 'User',
            'username'=> 'Username',
            'email' => 'Email',
            'nickname' => 'Nickname',
            'idcard' => 'Idcard',
            'sex' => 'Sex',
            'birthday' => 'Birthday',
            'place' => 'Place',
            'nation' => 'Nation',
            'marry' => 'Marry',
            'address' => 'Address',
            'contact' => 'Contact',
            'post' => 'Post',
            'phone' => 'Phone',
            'im' => 'Im',
            'politics' => 'Politics',
            'jobtitle' => 'Jobtitle',
            'job' => 'Job',
            'blog' => 'Blog',
            'pphoto' => 'Pphoto',
            'highest_education' => 'Highest Education',
            'graduation_date' => 'Graduation Date',
            'school' => 'School',
            'department' => 'Department',
            'specialities' => 'Specialities',
            'research_directions' => 'Research Directions',
            'work_experience' => 'Work Experience',
            'scientific_result' => 'Scientific Result',
            'achievement' => 'Achievement',
            'social_position' => 'Social Position',
            'n_second_school_major' => 'N Second School Major',
            'n_computer_skill' => 'N Computer Skill',
            'n_computer_achievement' => 'N Computer Achievement',
            'n_skill_mark' => 'N Skill Mark',
            'n_work' => 'N Work',
            'n_activity' => 'N Activity',
            's_admission_date' => 'S Admission Date',
            's_studentid' => 'S Studentid',
            's_school_position' => 'S School Position',
            'c_legal_person' => 'C Legal Person',
            'c_hr_manager' => 'C Hr Manager',
            'c_contacter_tel' => 'C Contacter Tel',
            'c_introduce_photo' => 'C Introduce Photo',
            'c_id_photo' => 'C Id Photo',
            'c_introduce' => 'C Introduce',
            'c_board_members' => 'C Board Members',
            'type_pg' => 'Type Pg',
            'type_p_vasn' => 'Type P Vasn',
            'type_g_pebg' => 'Type G Pebg',
            'open' => 'Open',
            'c_email' => 'C Email',
        );
    }


    public function rules() {
        $rules = array(
            array('username, email, idcard', 'required'),
            array('username', 'length', 'max'=>20, 'min' => 3,'message' => UserModule::t("Incorrect username (length between 3 and 20 characters).")),
            array('password', 'length', 'max'=>128, 'min' => 4,'message' => UserModule::t("Incorrect password (minimal length 4 symbols).")),
            array('email', 'email'),
            array('username', 'unique', 'message' => UserModule::t("This user's name already exists.")),
            array('email', 'unique', 'message' => UserModule::t("This user's email address already exists.")),
            array('verifyPassword', 'compare', 'compareAttribute'=>'password', 'message' => UserModule::t("Retype Password is incorrect.")),
            array('username', 'match', 'pattern' => '/^[A-Za-z0-9_]+$/u','message' => UserModule::t("Incorrect symbols (A-z0-9).")),

            array('user_id, sex, birthday, marry, politics, highest_education, type_pg, type_p_vasn, type_g_pebg, open', 'numerical', 'integerOnly'=>true),
            array('nickname, address, contact, blog, pphoto, n_second_school_major, n_skill_mark, c_introduce_photo, c_id_photo, n_activity, c_board_members', 'length', 'max'=>255),
            array('idcard, place, phone, jobtitle, job, s_studentid, c_legal_person, c_hr_manager', 'length', 'max'=>32),
            array('nation, school, department, specialities, social_position, s_school_position, c_contacter_tel, c_email', 'length', 'max'=>64),
            array('post, graduation_date, s_admission_date', 'length', 'max'=>8),
            array('im', 'length', 'max'=>12),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
        );
//        if (isset($_POST['ajax']) && $_POST['ajax']==='registration-form')
//            return $rules;
//        else
//            array_push($rules,array('verifyCode', 'captcha', 'allowEmpty'=>!UserModule::doCaptcha('registration')));
        return $rules;
    }

}